//
//  EcgNoTouchTipView.m
//  CareRingApp
//
//  Created by Linktop on 2024/4/2.
//

#import "EcgNoTouchTipView.h"

@implementation EcgNoTouchTipView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.titleLabel.text = _L(L_ECG_USE_TITL);
        [self.contentView addSubview:self.imageV];
        [self.contentView addSubview:self.txtView];
        
        [self.imageV mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.imageV.superview.mas_leading).offset(5);
            make.trailing.equalTo(self.imageV.superview.mas_trailing).inset(5);
            make.top.equalTo(self.titleLabel.mas_bottom);

        }];
        
        [self.txtView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.leading.trailing.equalTo(self.imageV);
            make.bottom.equalTo(self.txtView.superview.mas_bottom).inset(10);
            make.top.equalTo(self.imageV.mas_bottom).offset(5);
        }];
        
        
    }
    return self;
}

-(UIImageView *)imageV
{
    if (!_imageV) {
        _imageV = [UIImageView new];
        _imageV.image = [UIImage imageNamed:@"ecg_touch_bg"];
    }
    return _imageV;
}


-(UITextView *)txtView
{
    if (!_txtView) {
        _txtView = [UITextView new];
        _txtView.editable = NO;
        _txtView.attributedText = [[self class] resultDesc:_L(L_ECG_USE_DESC) Title:nil];
        _txtView.backgroundColor = UIColor.whiteColor;
    }
    return _txtView;
}

+(NSMutableAttributedString *)resultDesc:(NSString *)desc Title:(NSString *)titleString  {


    // 链接
    NSMutableAttributedString *allString = [[NSMutableAttributedString alloc]init];

    if (titleString.length) {

        NSString *str_sub_b = titleString;
        NSMutableAttributedString *sub_b = [[NSMutableAttributedString alloc] initWithString:str_sub_b];
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.lineSpacing = 8.0;
        paragraph.paragraphSpacing = 12.0;
        paragraph.alignment = NSTextAlignmentCenter;
        [sub_b addAttribute:NSParagraphStyleAttributeName
                                         value:paragraph
                                         range:NSMakeRange(0, [str_sub_b length])];
        [sub_b addAttributes: @{NSFontAttributeName : [UIFont fontWithName:FONT_ARIAL_BOLD size:20],
                                NSForegroundColorAttributeName : [UIColor whiteColor],

        } range:NSMakeRange(0, str_sub_b.length)];

        [allString appendAttributedString:sub_b];

    }
    

    //privacy label 富文本
    UIFont *privacyFont =  [UIFont systemFontOfSize:17.0];
    NSString *str_sub_a = desc;//@"Agree to Nexchair`s ";
    NSMutableAttributedString *privacyAttString = [[NSMutableAttributedString alloc]init];
    
    if (desc.length) {
        NSAttributedString *sub_a = [[NSAttributedString alloc] initWithString:str_sub_a attributes:@{NSFontAttributeName : privacyFont,
                                                                                                      NSForegroundColorAttributeName : [UIColor darkTextColor],}
                                     ];
        [privacyAttString appendAttributedString:sub_a];




        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.alignment = NSTextAlignmentLeft;
        paragraphStyle.lineSpacing = 5.0;
        paragraphStyle.paragraphSpacing = 8.0;
        [privacyAttString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, privacyAttString.string.length)];

        [allString appendAttributedString:privacyAttString];
    }

   

    return allString;
}



@end
